<form id="forms_group_form" method="post" action="/manager.php?app=forms&act=group_edit">
	<div class="tabs">
		<ul>
			<li><a href="#base">基本信息</a></li>
			!{if $group}
			<li><a href="#items">表单项</a></li>
			!{/if}
		</ul>
		<div id="base">
			!{if $site_langs|count eq 1}
			<div class="form_item">
				<strong>分组名称：</strong>
				<div><input class="text_input" maxlength="50" type="text" name="!{$cur_lang}_name" value="!{$group.$cur_lang.name}"/></div>
				<p>(名称长度应该在1至50之间)</p>
			</div>
			<div class="form_item">
				<strong>分组描述：</strong>
				<div><input class="text_input" maxlength="1000" type="text" name="!{$cur_lang}_desc" value="!{$group.$cur_lang.desc}"/></div>
			</div>
			!{else}
			<div class="tabs">
				<ul>
					!{foreach from=$site_langs item=lan_name key=lan}
					<li><a href="#lan_!{$lan}">!{$lan_name}</a></li>
					!{/foreach}
				</ul>
				!{foreach from=$site_langs item=lan_name key=lan}
				<div id="lan_!{$lan}">
					<div class="form_item">
						<strong>分组名称：</strong>
						<div><input class="text_input" maxlength="50" type="text" name="!{$lan}_name" value="!{$group.$lan.name}"/></div>
						<p>(名称长度应该在1至50之间)</p>
					</div>
					<div class="form_item">
						<strong>分组描述：</strong>
						<div><input class="text_input" maxlength="1000" type="text" name="!{$lan}_desc" value="!{$group.$lan.desc}"/></div>
					</div>
					
				</div>
				!{/foreach}
			</div>
			!{/if}
		</div>
		!{if $group}
		<div id="items">
			<table class="list_table" id="group_item_tab">
				<tr>
					<th>名称</th>
					<th>多语言</th>
					<th>类型</th>
				</tr>
			!{foreach from=$ungroups item=item key=tid}
				<tr class="item_tr" item_id="!{$tid}">
					<td>
						<label><input type="checkbox" name="items[]" value="!{$tid}" !{if $item.selected}checked="checked"!{/if}/> !{$item.name} !{if $item.desc}<span>(!{$item.desc})</span>!{/if}</label>
					</td>
					<td>!{if $item.mutil_lan}<span class="ui-icon ui-icon-check"></span>!{else}<span class="ui-icon ui-icon-close"></span>!{/if}</td>
					<td>!{$item.type_name} <span>[!{if $item.trait}!{$item.trait_name}!{/if}]</span></td>
				</tr>
			!{foreachelse}
				<tr>
					<td colspan="3">还没有添加属性！</td>
				</tr>
			!{/foreach}
			</table>
		</div>
		!{/if}
	</div>
	<div class="form_item form_btn_item">
		<input type="hidden" name="id" value="!{$id}"/>
		<input type="hidden" name="gid" value="!{$group._id|default:'0'}"/>
		<input class="button submit_btn" type=button value="保存" />
	</div>
</form>
<script>
	var cur_g_item_ids = '';
	$(function(){
		$('#forms_group_form').ajax_form({
			'submit_btn' : '.submit_btn',
			'success' : function(form, data){
				window.location.href = '/manager.php?app=attrs&act=edit&module=forms&id=!{$id}#form_group';
				window.location.reload();
			}
		});
		$("#forms_group_form .button").button();
		$("#forms_group_form .tabs").tabs();

		$("#group_item_tab").sortable({
			items : '.item_tr',
			stop: function(event, ui){
				setTimeout(function(){
					var g_item_ids = get_group_item_ids();
					if(cur_g_item_ids != g_item_ids){
						//有修改，提交到服务器
						var url = '/manager.php?app=forms&act=group_item_sort&id=!{$id}';
						$.post(url,{
								gid : '!{$group._id|default:'0'}',
								item_ids : g_item_ids
							}, function(data){
							var json = eval('(' + data + ')');
							alert(json.info);
							if(json.result){
								
							}
						});
						cur_g_item_ids = g_item_ids;
					}
				}, 500);
			}
		});
		cur_g_item_ids = get_group_item_ids();
	});

	function get_group_item_ids(){
		var g_item_ids = '';
		$('#group_item_tab .item_tr').each(function(){
			g_item_ids += $(this).attr('item_id') + ',';
		});
		return g_item_ids;
	}
</script>